from typing import Dict
from PySide6.QtWidgets import QTreeWidgetItem
from .TreeWidgetItemABC import TreeWidgetItemABC

class TreeWidgetItemCanPdu(TreeWidgetItemABC):
    '''
    description:
        用于展示 CANPDU 的 TreeWidgetItem 对象
    CANMessage字典结构:
    '''
    def __init__(self, d_data: 'dict' = dict()) -> None:
        super().__init__(d_data=d_data)

    
    def Refresh(self, d_data: 'dict') -> None:
        # return super().Refresh(d_data)
        self.setText(0, str(d_data['time']))
        self.setText(1, str(d_data['channel']))
        self.setText(2, '-')
        self.setText(3, d_data['name'])
        self.setText(4, d_data['eventType'])
        self.setText(5, d_data['direction'])
        self.setText(6, str(d_data['dlc']))
        self.setText(7, d_data['data'].hex())
        if (len(d_data['children']) > 0):
            for i_ in d_data['children']:
                item_ = QTreeWidgetItem()
                item_.setText(0, i_['name'])
                item_.setText(1, str(i_['value']))
                item_.setText(2, i_['mean'])
                self.addChild(item_)

